package hu.ikti.oamadmin.types.entities;

import hu.ikti.oamadmin.utlis.FileUtil;

import java.io.IOException;
import java.net.URL;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.SequenceGenerator;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Table;

@Entity
@Table(name = "BYTECODE")
@SequenceGenerator(sequenceName = "BYTECODE_SEQ", name = "BC_SEQ", allocationSize = 1)
public class ByteCode {

	private Long id;
	private byte[] bytes;

	public ByteCode() {
	}

	public ByteCode(URL url) throws IOException {
		bytes = FileUtil.getBytesFromURL(url);
	}

	@Id
	@Column(name = "ID")
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "BC_SEQ")
	public Long getId() {
		return id;
	}

	@Column(name = "BYTE_CODE_ARRAY", nullable = false)
	@Lob
	public byte[] getBytes() {
		return bytes;
	}

	public void setBytes(byte[] bytes) {
		this.bytes = bytes;
	}

	public void setId(Long id) {
		this.id = id;
	}

}